//
//  MyViewController.m
//  大轮胎
//
//  Created by 朱永超 on 2017/3/16.
//  Copyright © 2017年 zyc. All rights reserved.
//

#import "MyViewController.h"
#import <SDAutoLayout.h>
#import "MyTableViewController.h"
#import "MyBarViewController.h"
#import "MyButtonViewController.h"
@interface MyViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    
    NSArray * titleArr;//单元格标题
    UIButton * button2;
}
@property(nonatomic,strong)UITableView * table;
@property(nonatomic,strong)NSArray * colorarr;

@end

@implementation MyViewController
-(void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden=NO;
    self.navigationController.navigationBar.hidden=YES;
    [_table reloadData];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    self.view.backgroundColor=[UIColor colorWithRed:117/255.0 green:211/255.0 blue:186/255.0 alpha:1.0];
    self.navigationController.navigationBar.hidden=YES;
    //底层图片
    UIImageView * image=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    image.image=[UIImage imageNamed:@"背景1"];
    image.userInteractionEnabled=YES;
    [self.view addSubview:image];
    //左上角设置按钮
    UIButton * btSet=[[UIButton alloc]initWithFrame:CGRectMake(20, 40, 30, 30)];
    [btSet setBackgroundImage:[UIImage imageNamed:@"设置"] forState:0];
    [btSet addTarget:self action:@selector(clickSet) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btSet];
    
    //用户头像
    UIButton * button=[UIButton buttonWithType:UIButtonTypeCustom];
    //button.frame=CGRectMake((self.view.frame.size.width)/2-50, self.view.frame.size.height/5-52, 100, 100);
    button.layer.masksToBounds=YES;
    button.layer.cornerRadius=50;
    //button.alpha = 0.1;
    button.backgroundColor=[UIColor cyanColor];
    [button setBackgroundImage:[UIImage imageNamed:@"2"] forState:0];
    [button addTarget:self action:@selector(SkipSignInView) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    button.sd_layout.widthIs(100).heightIs(100).leftSpaceToView(self.view,self.view.frame.size.width/2-50).topSpaceToView(self.view,self.view.frame.size.height/5-52);
    //表格
    //_table=[[UITableView alloc]initWithFrame:CGRectMake(0,self.view.frame.size.height-485, self.view.frame.size.width, self.view.frame.size.height-200) style:UITableViewStyleGrouped];
    _table=[[UITableView alloc]init];
    _table.userInteractionEnabled=YES;
    _table.backgroundColor = [UIColor clearColor];
    _table.contentInset=UIEdgeInsetsMake(100, 0, 0, 0);
    _table.delegate=self;
    _table.dataSource=self;
    [self.view addSubview:_table];
    _table.sd_layout.widthIs(self.view.frame.size.width).heightIs(self.view.frame.size.height-238).leftSpaceToView(self.view,0).rightSpaceToView(self.view,0).topSpaceToView(self.view,self.view.frame.size.height/5+50);
    //登陆/注册按钮
    button2=[[UIButton alloc]init];
    [button2 setTitle:@"登录 / 注册" forState:0];
    [button2 setTintColor:[UIColor whiteColor]];
    [button2 addTarget:self action:@selector(SkipSignInView2) forControlEvents:UIControlEventTouchUpInside];
    button2.userInteractionEnabled = YES;
    [self.view addSubview:button2];
    button2.sd_layout.widthIs(100).heightIs(30).leftSpaceToView(self.view,self.view.frame.size.width/2-50).topSpaceToView(self.view,self.view.frame.size.height/5+65);
    
    
    
    //表格颜色数组
    _colorarr=@[[UIColor colorWithRed:253/255.0 green:101/255.0 blue:65/255.0 alpha:1.0],
                [UIColor colorWithRed:253/255.0 green:133/255.0 blue:68/255.0 alpha:1.0],
                [UIColor colorWithRed:253/255.0 green:160/255.0 blue:89/255.0 alpha:1.0],
                [UIColor colorWithRed:253/255.0 green:178/255.0 blue:82/255.0 alpha:1.0],
                [UIColor colorWithRed:185/255.0 green:195/255.0 blue:121/255.0 alpha:1.0],
                [UIColor colorWithRed:152/255.0 green:202/255.0 blue:151/255.0 alpha:1.0],
                [UIColor colorWithRed:117/255.0 green:211/255.0 blue:186/255.0 alpha:1.0]];
    
    
}
-(void)clickSet
{
    MyBarViewController * MyBarVC=[[MyBarViewController alloc]init];
    [self.navigationController pushViewController:MyBarVC animated:NO];
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if ([scrollView isEqual:_table]) {
        //        NSLog(@"%f",_table.contentOffset.y);
        if (_table.contentOffset.y  >-62) {
            button2.hidden=YES;
            
        }
        else{
            button2.hidden=NO;
        }
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 75;
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 7;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *  cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    //单元格标题
    titleArr=@[@"我的资产",@"全部订单",@"购物清单",@"我的收藏",@"我的关注",@"我的分享",@"意见反馈",];
    
    [cell.textLabel setTintColor:[UIColor whiteColor]];
    cell.backgroundColor=_colorarr[indexPath.row];
    cell.textLabel.text=titleArr[indexPath.row];
    cell.textLabel.font=[UIFont systemFontOfSize:20];
    cell.imageView.image=[UIImage imageNamed:@"轮胎"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.layer.cornerRadius = 10;
    cell.layer.masksToBounds = YES;
    return cell;
    
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"-----");
    UITableViewCell* CellAtIndex = [tableView cellForRowAtIndexPath:indexPath];
    CGRect frame2 = CellAtIndex.frame;
    //frame2.size.height += 10;
    [CellAtIndex setFrame:frame2];
    MyTableViewController * MyTableVC=[[MyTableViewController alloc]init];
    [self.navigationController pushViewController:MyTableVC animated:NO];
}
-(void)SkipSignInView
{
    NSLog(@"++++++++++");
    
    
    MyTableViewController * MyTableVC=[[MyTableViewController alloc]init];
    [self.navigationController pushViewController:MyTableVC animated:NO];
}
-(void)SkipSignInView2
{
    NSLog(@"========");
    MyButtonViewController * MyButtonVC=[[MyButtonViewController alloc]init];
    [self.navigationController pushViewController:MyButtonVC animated:NO];
}

@end
